﻿using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DevExpress.Xpo;
using OT.Module.Model;
using OT.BaseLibrary;

namespace PureTest
{
    /// <summary>
    /// UnitTest1 的摘要说明
    /// </summary>
    [TestClass]
    public class ComboxTest
    {
        public ComboxTest()
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
        }

        #region 其他测试属性
        //
        // 您可以在编写测试时使用下列其他属性:
        //
        // 在运行类中的第一个测试之前使用 ClassInitialize 运行代码
        // [ClassInitialize()]
        // public static void MyClassInitialize(TestContext testContext) { }
        //
        // 在类中的所有测试都已运行之后使用 ClassCleanup 运行代码
        // [ClassCleanup()]
        // public static void MyClassCleanup() { }
        //
        // 在运行每个测试之前使用 TestInitialize 运行代码 
        // [TestInitialize()]
        // public void MyTestInitialize() { }
        //
        // 在运行每个测试之后使用 TestCleanup 运行代码
        // [TestCleanup()]
        // public void MyTestCleanup() { }
        //
        #endregion

        #region GenProvinceCity

        [TestMethod]
        public void GenProvinceCity()
        {
            Session xpo = DataSource.GetSession();

            Province prov = new Province(xpo);
            prov.ID = CommonService.ReturnMax();
            prov.Name = "广东省";
            prov.Save();

            List<string> citys = new List<string>();
            citys.Add("广州");
            citys.Add("清远");
            citys.Add("佛山");
            citys.Add("从化");
            CreateCity(xpo, prov, citys);

            prov = new Province(xpo);
            prov.ID = CommonService.ReturnMax();
            prov.Name = "广西省";
            prov.Save();

            citys = new List<string>();
            citys.Add("桂林");
            citys.Add("南宁");
            citys.Add("柳州");
            citys.Add("百色");
            CreateCity(xpo, prov, citys);

            prov = new Province(xpo);
            prov.ID = CommonService.ReturnMax();
            prov.Name = "湖南省";
            prov.Save();

            citys = new List<string>();
            citys.Add("长沙");
            citys.Add("衡阳");
            citys.Add("郴州");
            citys.Add("冷水滩");
            CreateCity(xpo , prov, citys);
        }
        #endregion

        #region CreateCity

        private void CreateCity(Session xpo , Province prov, List<string> citys)
        {
            foreach (string cityName in citys)
            {
                City city = new City(xpo);
                city.ID = CommonService.ReturnMax();
                city.Name = cityName;
                city.BelongProvince = prov;
                city.Save();
            }
        }

        #endregion

        #region GenCompanyDepartment

        [TestMethod]
        public void GenCompanyDepartment()
        {
            Session xpo = DataSource.GetSession();

            Company company = new Company(xpo);
            company.CompanyID = CommonService.ReturnMax();
            company.CompanyName = "东方思维";
            company.Save();

            List<string> depts = new List<string>();
            depts.Add("研发部");
            depts.Add("财务部");
            depts.Add("行政部");
            CreateDepartment(xpo, company, depts);

            company = new Company(xpo);
            company.CompanyID = CommonService.ReturnMax();
            company.CompanyName = "南粤集团";
            company.Save();

            depts = new List<string>();
            depts.Add("投资部");
            depts.Add("党群部");
            depts.Add("人事部");
            CreateDepartment(xpo, company, depts);

        }

        #endregion

        #region CreateDepartment

        private void CreateDepartment(Session xpo, Company company, List<String> depts)
        {
            foreach (string deptName in depts)
            {
                Department dept = new Department(xpo);
                dept.ID = CommonService.ReturnMax();
                dept.Name = deptName;
                dept.BelongCompany = company;
                dept.Save();
            }

        }

        #endregion
    }
}
